package com.xiaoluo.web.form;

import com.xiaoluo.cd.entity.base.ProjServers;
import com.xiaoluo.cd.entity.base.Projects;
import com.xiaoluo.cd.entity.base.Servers;

import java.util.List;

/**
 * Project : XL-CD
 * Package : com.xiaoluo.web.form
 * Created by Willian.
 * Date  : 2016/1/7 14:32.
 */
public class ProjectForm extends Projects {

    private List<Servers> buildServers;

    private List<Servers> testServers;

    private List<Servers> productServers;

    private List<Servers> quickServers;

    public List<Servers> getQuickServers() {
        return quickServers;
    }

    public void setQuickServers(List<Servers> quickServers) {
        this.quickServers = quickServers;
    }

    public List<Servers> getBuildServers() {
        return buildServers;
    }

    public void setBuildServers(List<Servers> buildServers) {
        this.buildServers = buildServers;
    }

    public List<Servers> getTestServers() {
        return testServers;
    }

    public void setTestServers(List<Servers> testServers) {
        this.testServers = testServers;
    }

    public List<Servers> getProductServers() {
        return productServers;
    }

    public void setProductServers(List<Servers> productServers) {
        this.productServers = productServers;
    }

    public String getBuildServersHost(){
        return getHost(buildServers);
    }

    public String getBuildServersPwd(){
        return getPassWord(buildServers);
    }

    public String getTestServersHost(){
        return getHost(testServers);
    }
    public String getTestServersPwd(){
        return getPassWord(testServers);
    }
    public String getProductServersHost() {
        return getHost(productServers);
    }
    public String getProductServersPwd(){
        return getPassWord(productServers);
    }

    public String getQuickServersHost() {
        return getHost(quickServers);
    }
    public String getQuickServersPwd(){
        return getPassWord(quickServers);
    }

    /**
     * userName@127.0.0.1:22: 123456
     * @param serverses
     * @return
     */
    private String getPassWord(List<Servers> serverses){
        if(serverses != null && serverses.size() >0){
            StringBuffer buffer = new StringBuffer();
            for(Servers server:serverses){
                buffer.append("'").append(server.getUserName()).append("@").append(server.getIp())
                        .append(":").append(server.getPort()).append("': '").append(server.getPassWord()).append("'").append(",");
            }
            return  buffer.toString();
        }
        return "";
    }

    /**
     * userName@127.0.0.1:22
     * @param serverses
     * @return
     */
    private String getHost(List<Servers> serverses){
        if(serverses != null && serverses.size() >0){
            StringBuffer buffer = new StringBuffer();
            for(Servers server:serverses){
                if(server.getPort() != null && server.getPort() != 22){
                    buffer.append("'").append(server.getUserName()).append("@").append(server.getIp()).append(":").append(server.getPort()).append("'").append(",");
                }else {
                    buffer.append("'").append(server.getUserName()).append("@").append(server.getIp()).append("'").append(",");
                }
            }
            return  buffer.toString();
        }
        return "";
    }
}
